﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers.fountain {
    import net.wooga.pets.loading.vos.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.models.world.vos.actors.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.world.*;

    public class FinalizeRegenerationCommand extends Command {

        public var event:InfoEvent;
        public var world:WorldModel;

        override public function execute():void{
            var _local1:Object = {taskType:GameConstants.TREAT_ELDER, itemType:GameConstants.ANY_TYPE, onResult:this.onResult};
            var _local2:RequestVO = new RequestVO("finalize_fountain", {id:this.event.id});
            var _local3:Array = [_local2];
            var _local4:TaskRequestEvent = new TaskRequestEvent(EventConstants.SEND_TASK_REQUEST, _local3, _local1);
            dispatch(_local4);
            dispatch(new InfoEvent(EventConstants.PLAY_EFFECT_SOUND, GameConstants.SOUND_START_FONTAIN));
            this.track();
        }
        private function onResult(_arg1:ResultVO):void{
            var _local2:Object;
            var _local3:IRoom;
            var _local4:ITreatable;
            var _local5:int;
            var _local6:int;
            var _local7:Object;
            if (_arg1.success){
                _local2 = _arg1.data.finalize_fountain;
                _local3 = (this.world.getRoomOfActor(this.event.id) as IRoom);
                _local3.machine.state = WorldConstants.CLEAN;
                _local4 = (this.world.getActor(this.event.id) as ITreatable);
                _local5 = _local4.treatments[0].xp;
                _local6 = _local4.treatments[0].coins;
                _local7 = {speaker:(_local4.type + "YoungBubble"), patientId:_local4.id, patientType:_local4.type, xp:_local5, coins:_local6};
                dispatch(new InfoEvent(EventConstants.CREATE_POPUP, GameConstants.FOUNTAIN_RESULT_POPUP, _local7));
                dispatch(new InfoEvent(EventConstants.ON_TREATMENT_FINALIZED, this.event.id, _local2));
                dispatch(new InfoEvent(EventConstants.UPDATE_USER_DATA, null, _local2));
                dispatch(new InfoEvent(EventConstants.HANDLE_NEXT_IN_QUEUE, _local3.type));
            };
        }
        private function track():void{
            var _local1:PatientVO = (this.event.info as PatientVO);
            var _local2:String = _local1.petDisease;
            var _local3:String = ("gems_needed_" + this.getSymbolsAsString(_local1));
            var _local4:Object = {type:"fountain", subtype1:"elder_healed", subtype2:_local2, subtype3:_local3};
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.EVENT, _local4));
        }
        private function getSymbolsAsString(_arg1:PatientVO):int{
            var _local4:String;
            var _local2:Object = (_arg1.currentTreatment) ? _arg1.currentTreatment.symbols : {};
            var _local3:int;
            for (_local4 in _local2) {
                _local3 = (_local3 + _local2[_local4]);
            };
            return (_local3);
        }

    }
}//package net.wooga.pets.controllers.fountain 
